<?php
require_once './application/core/CoreBase.php';
require_once './application/core/Sonde/indexCore.php';
require_once './application/core/Client/sondeSoap.php';

class writeConf extends IndexCore
{
    private $_conf;
    private $_param;
    private $_c;
    private $_arr;
    private $_values;
    private $_section;
    private $_title;
    private $_obj;
    private $_p;
    private $_xmlTmp;

    public function writeConfiguration()
    {
        $this->_conf = $this->_controller->getRequest()->getParam('conf');
        $this->_conf = $this->parseConfiguration();
        $this->_conf = base64_encode($this->_conf);
        $this->_param = array( 'action'=> 'write',
                'conf' => $this->_conf );
        $this->_c = new sondeSoap( $this->_controller );
        $this->_c->read( $this->_param, 'sondereadwrite' );
    }

    private function parseConfiguration()
    {
        $this->_obj = new SimpleXMLElement("<configuration></configuration>");
        $this->_arr = explode("-", $this->_conf);
        foreach ( $this->_arr as $this->_section )
        {
            $this->_section = explode( ",", $this->_section );
            $this->_p = '0';
            foreach ($this->_section as $this->_values )
            {
                if ( preg_match("/^<b>/", $this->_values ) == '1' )
                {
                    $this->_title = preg_replace("/\<[\/]?b\>/", "", $this->_values );
                    $this->_title = $this->_obj->addChild( $this->_title );
                }
                elseif ( preg_match("/^<\/span>/", $this->_values ) == '1' || empty($this->_values) )
                    continue;
                else
                {
                    if ( $this->_p == '0')
                    {
                        $this->_xmlTmp = $this->_values;
                        $this->_p = '1';
                    }
                    else
                    {
                        $this->_title->addChild($this->_xmlTmp, $this->_values);
                        $this->_p = '0';
                    }
                }
            }
        }
        return $this->_obj->asXML();
    }

}
?>